package org.example.tails.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.tails.common.Result;
import org.example.tails.pojo.Emp;
import org.example.tails.pojo.LoginInfo;
import org.example.tails.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @RequestMapping("/login")
    public Result Login(@RequestBody Emp emp){
        log.info("用户登录，用户名：{}",emp.getName());
        LoginInfo info=loginService.login(emp);

        if(info!=null){
             return Result.success(info);
        }
        return Result.fail("用户名或密码错误");
    }

    @RequestMapping(value="/logout")
    public Result logout(@RequestBody Emp emp){
        return Result.success("退出登录成功");
    }
}
